home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 11 / FM Towns Free Software Collection 11.iso / t_os / tool / artemis1 / src / geasm.asm < prev    next >
Encoding:
Assembly Source File  |  1993-10-03  |  20.3 KB  |  1,039 lines

  1. comment $
  2.     ARTemis (Graphic Editor for FM-TOWNS)
  3.     (c) MATSUUCHI Ryosuke 1992,1993
  4.  
  5.     geasm.asm
  6.  
  7.   ルーチン一覧:
  8.  
  9.                 ws_segment
  10.                 ws_pokew
  11.                 ws_peekw
  12.  
  13.                 viewscr_down
  14.                 viewscr_sub
  15.  
  16.                 xmemcpy
  17.                 xymemcpy
  18.                 xyzoommemcpy
  19.  
  20.                 graypset
  21.                 graypset_list
  22.                 _graypset
  23.                 _graypset_list
  24.                 _graypset_sub
  25.  
  26.                 MEMstoreword
  27.                 MEMstoreword_xor
  28. $
  29.  
  30.                 public    xmemcpy, xymemcpy, graypset, _graypset, _graypset_sub, graypset_list
  31.                 public    viewscr_sub,viewscr_down
  32.                 public    ws_segment, ws_pokew, ws_peekw
  33.                 public    MEMstoreword_xor, MEMstoreword
  34.                 public    pict_makeicon32k
  35.                 public    pict_makeicon16
  36.                 public    makeHLSgradline
  37.                 extrn    _wrtpage:dword, _nowscrmod:dword
  38.  
  39.                 assume cs:cseg, ds:cseg
  40.  
  41. dseg segment
  42.  
  43.     oldint24p    dw    0
  44.                 dd    0
  45.     oldint24r    dd    0
  46.  
  47.     wk0            dd    0
  48.     wk1            dd    0
  49.     wk2            dd    0
  50.  
  51. dseg ends
  52.  
  53.  
  54. cseg segment
  55.  
  56. .comment @
  57.  
  58. ;----------------------------------------------------------------------
  59. ;void ARTsetint24H(void)
  60. ;----------------------------------------------------------------------
  61.  
  62.  
  63. __int24Hhandle    proc
  64.                 
  65.                 iret
  66.                 
  67. __int24Hhandle    endp
  68.  
  69.  
  70. ARTsetint24H    proc
  71.                 mov        ax,2502h    ; INT 24h のネイティブ割り込みベクタを得る
  72.                 mov        cl,24h
  73.                 int        21h
  74.                 mov        ax,es
  75.                 mov        [oldint24p],ax
  76.                 mov        [oldint24p+4],ebx
  77.                 mov        ax,2503h    ; INT 24h のリアル割り込みベクタを得る
  78.                 mov        cl,24h
  79.                 int        21h
  80.                 mov        [oldint24r],ebx
  81.                 mov        ax,2506h    ; INT 24h の割り込みを常にネイティブで受ける
  82.                 mov        cl,24h
  83.                 mov        ax,cs
  84.                 mov        ds,ax
  85.                 mov        
  86.                 
  87. ARTsetint24H    endp
  88.  
  89. ;----------------------------------------------------------------------
  90. ;void ARTresetint24H(void)
  91. ;----------------------------------------------------------------------
  92.  
  93. @
  94.  
  95. ;----------------------------------------------------------------------
  96. ;void pict_makeicon32k(char *grpbuf, int xlen, int ylen, char *bitbuf)
  97. ;----------------------------------------------------------------------
  98.  
  99.  
  100. pict_makeicon32k proc
  101.                 cld
  102.                 pushfd                            ;+
  103.                 push    ebx                        ;++
  104.                 push    esi                        ;+++
  105.                 push    edi                        ;++++
  106.                 mov     ax,es                    ; es := ds
  107.                 push    eax                        ;+++++
  108.                 mov     ax,ds
  109.                 mov     es,ax
  110.                 #para0 equ 4+20
  111.                 mov     edi,[esp+#para0]        ; edi : outputbuf-pointer
  112.                 mov     esi,[esp+#para0+12]     ; esi : bitbuf-pointer
  113.                 mov     ebx,[esp+#para0+8]        ; ebx : y-counter(down)
  114.                 or        ebx,ebx
  115.                 jz        #loopend0
  116.                 #looptop0:
  117.                     mov     ecx,[esp+#para0+4]    ; ecx : x-counter(down)
  118.                     push    esi                    ;++++++
  119.                     #looptop1:
  120.                         mov     dl,[esi]        ; dl := bit pattern
  121.                         rept 4
  122.                          sub    eax,eax
  123.                          rol    dl,1
  124.                          sbb    eax,0
  125.                          sub    ax,ax
  126.                          rol    dl,1
  127.                          sbb    ax,0
  128.                          rol    eax,16
  129.                          not    eax
  130.                          stosd
  131.                          sub    ecx,2
  132.                          jz     #loopend1
  133.                          jc     #loopend1
  134.                         endm
  135.                         inc     esi
  136.                     jmp #looptop1
  137.                     #loopend1:
  138.                     pop     esi                    ;+++++
  139.                     mov     ecx,[esp+#para0+4]    ; ecx := (xlen+7)/8
  140.                     add     ecx,7
  141.                     shr     ecx,3
  142.                     add     esi,ecx
  143.                     dec     ebx
  144.                 jnz     #looptop0
  145.                 #loopend0:
  146.                 pop     eax                        ;++++
  147.                 mov     es,ax
  148.                 pop     edi                        ;+++
  149.                 pop     esi                        ;++
  150.                 pop     ebx                        ;+
  151.                 popfd                            ;
  152.                 ret
  153. pict_makeicon32k endp
  154.  
  155.  
  156. ;----------------------------------------------------------------------
  157. ;void pict_makeicon16(char *grpbuf, int xlen, int ylen, char *bitbuf)
  158. ;----------------------------------------------------------------------
  159.  
  160.  
  161. pict_makeicon16    proc
  162.                 ;レジスタ退避
  163.                 pushfd
  164.                 push    ebx
  165.                 push    esi
  166.                 push    edi
  167.                 mov        ax,es
  168.                 push    eax
  169.                 mov        ax,ds
  170.                 mov        es,ax
  171.                 #para equ 4+20
  172.                 ;
  173.                 mov        edi,[esp+#para]
  174.                 mov        esi,[esp+#para+12]
  175.                 mov        ebx,[esp+#para+8]            ;ebx := y-counter(down)
  176.                 or        ebx,ebx
  177.                 jz        #loopend1
  178.                 #looptop1:
  179.                     mov        ecx,[esp+#para+4]        ;ecx := x-counter(down)
  180.                     push    esi
  181.                     #looptop0:
  182.                         sub        eax,eax
  183.                         mov        dl,[esi]
  184.                         rept 4
  185.                             sub        dh,dh
  186.                             rol        dl,1
  187.                             sbb        dh,0
  188.                             and        dh,00eh
  189.                             or        al,dh
  190.                             sub        dh,dh
  191.                             rol        dl,1
  192.                             sbb        dh,0
  193.                             and        dh,0e0h
  194.                             or        al,dh
  195.                             ror        eax,8
  196.                         endm
  197.                         not        eax
  198.                         stosd
  199.                         sub        ecx,8
  200.                         jz        #loopend0
  201.                         jc        #loopend0
  202.                         inc        esi
  203.                     jmp    #looptop0
  204.                     #loopend0:
  205.                     pop        esi
  206.                     mov        ecx,[esp+#para+4]
  207.                     add        ecx,7
  208.                     shr        ecx,3
  209.                     add        esi,ecx
  210.                     dec    ebx
  211.                 jnz    #looptop1
  212.                 #loopend1:
  213.                 ;レジスタ復帰
  214.                 pop        eax
  215.                 mov        es,ax
  216.                 pop        edi
  217.                 pop        esi
  218.                 pop        ebx
  219.                 popfd
  220.                 ret
  221. pict_makeicon16    endp
  222.  
  223.  
  224. ;---------------------------------------------------------------
  225. ;void ws_segment(int seg)
  226. ;void ws_pokew(int ofs, int data)
  227. ;int  ws_peekw(int ofs)
  228. ;---------------------------------------------------------------
  229.  
  230.  
  231. ws_segment        proc
  232.                 mov     eax,[esp+4]
  233.                 mov     fs,ax
  234.                 ret
  235. ws_segment        endp
  236.  
  237.  
  238. ws_pokew        proc
  239.                 mov     eax,[esp+4]
  240.                 mov     ecx,[esp+8]
  241.                 mov     fs:[eax],cx
  242.                 ret
  243. ws_pokew        endp
  244.  
  245.  
  246. ws_peekw        proc
  247.                 sub     eax,eax
  248.                 mov     ecx,[esp+4]
  249.                 mov     ax,fs:[eax]
  250.                 ret
  251. ws_peekw        endp
  252.  
  253.  
  254. ;---------------------------------------------------------------
  255. ;void viewscr_down(char *d_adrs, char *s_adrs, char *cmd)
  256. ;---------------------------------------------------------------
  257.  
  258. viewscr_down    proc
  259.                 pushfd
  260.                 push    ebx
  261.                 push    esi
  262.                 push    edi
  263.                 cld
  264. #para    equ     4*4+4
  265.                 mov     edi,[esp+#para]
  266.                 mov     esi,[esp+#para+4]
  267.                 mov     edx,[esp+#para+8]
  268.                 mov     eax,80000000h
  269.                 xor     ecx,ecx
  270.                 #6:
  271.                         mov     cl,ds:[edx]
  272.                         inc     edx
  273.                         jmp     [#jmptbl+ecx*4]
  274.                 #5:
  275.                 pop     edi
  276.                 pop     esi
  277.                 pop     ebx
  278.                 popfd
  279.                 ret
  280. #shift4bit:
  281.                 shr     ebx,4
  282.                 jmp     #6
  283. #shift8bit:
  284.                 shr     ebx,8
  285.                 jmp     #6
  286. #shift12bit:
  287.                 shr     ebx,12
  288.                 jmp     #6
  289. #shift16bit:
  290.                 shr     ebx,16
  291.                 jmp     #6
  292. #shift20bit:
  293.                 shr     ebx,20
  294.                 jmp     #6
  295. #shift24bit:
  296.                 shr     ebx,24
  297.                 jmp     #6
  298. #store4bit:
  299.                 shrd    eax,ebx,4
  300.                 jnc     #6
  301.                 mov     ds:[edi],eax
  302.                 add     edi,4
  303.                 mov     eax,80000000h
  304.                 jmp     #6
  305. #store8bit:
  306.                 shrd    eax,ebx,8
  307.                 jnc     #6
  308.                 mov     ds:[edi],eax
  309.                 add     edi,4
  310.                 mov     eax,80000000h
  311.                 jmp     #6
  312. #store12bit:
  313.                 shrd    eax,ebx,12
  314.                 jnc     #6
  315.                 mov     ds:[edi],eax
  316.                 add     edi,4
  317.                 mov     eax,80000000h
  318.                 jmp     #6
  319. #getnewDW:
  320.                 mov     ebx,ds:[esi]
  321.                 add     esi,4
  322.                 jmp     #6
  323.  
  324. #jmptbl         dd        #5,#store4bit,#shift4bit,#getnewDW
  325.                 ;        0    1           2          3
  326.                 dd        #shift8bit,#shift12bit,#shift16bit
  327.                 ;         4            5            6
  328.                 dd        #store8bit,#store12bit,#shift20bit,#shift24bit
  329.                 ;         7            8            9             10
  330.  
  331. viewscr_down    endp
  332.  
  333.  
  334.  
  335. ;---------------------------------------------------------------
  336. ;void viewscr_sub(d_seg, d_adrs, char *s_adrs, char *cmd)
  337. ;---------------------------------------------------------------
  338.  
  339.  
  340. viewscr_sub     proc
  341.                 pushfd
  342.                 push    ebx
  343.                 push    esi
  344.                 push    edi
  345.                 mov     bx,es
  346.                 push    ebx
  347.                 cld
  348. #para    equ     4*5+4
  349.                 mov     eax,[esp+#para]
  350.                 mov     es,ax
  351.                 mov     edi,[esp+#para+4]
  352.                 mov     esi,[esp+#para+8]
  353.                 mov     edx,[esp+#para+12]
  354.                 mov     eax,80000000h
  355.                 #6:
  356.                         xor     ecx,ecx
  357.                         mov     cl,ds:[edx]
  358.                         inc     edx
  359.                         jmp     [#jmptbl+ecx*4]
  360.                         
  361.                         
  362. ;                        cmp     cl,2            ;転送元 DW を右4ビットシフト
  363. ;                        jnz     #0
  364. ;                                shr     ebx,4
  365. ;                                jmp     #1
  366. ;                        #0:
  367. ;                        cmp     cl,1            ;[転送元DW:転送先DW]を右4ビットシフト
  368. ;                        jnz     #2
  369. ;                                shrd    eax,ebx,4
  370. ;                                jnc     #3
  371. ;                                        stosd
  372. ;                                        mov     eax,80000000h
  373. ;                                #3:
  374. ;                                jmp     #1
  375. ;                        #2:
  376. ;                        cmp     cl,3            ;転送元DW を新たに読み込む
  377. ;                        jnz     #4
  378. ;                                xchg    eax,ebx
  379. ;                                lodsd
  380. ;                                xchg    eax,ebx
  381. ;                                jmp     #1
  382. ;                        #4:
  383. ;                                jmp     #5                ;終了
  384. ;                        #1:
  385. ;                        inc     edx
  386. ;                jmp     #6
  387.  
  388.  
  389.                 #5:
  390.                 pop     ebx
  391.                 mov     es,bx
  392.                 pop     edi
  393.                 pop     esi
  394.                 pop     ebx
  395.                 popfd
  396.                 ret
  397.  
  398.  
  399. #shift4bit:
  400.                 shr     ebx,4
  401.                 jmp     #6
  402. #store4bit:
  403.                 shrd    eax,ebx,4
  404.                 jnc     #6
  405.                 stosd
  406.                 mov     eax,80000000h
  407.                 jmp     #6
  408.  
  409. #getnewDW:
  410.                 xchg    eax,ebx
  411.                 lodsd
  412.                 xchg    eax,ebx
  413.                 jmp     #6
  414.  
  415. #jmptbl         dd        #5,#store4bit,#shift4bit,#getnewDW
  416.  
  417.  
  418.  
  419.  
  420. viewscr_sub     endp
  421.  
  422.  
  423.  
  424. ;---------------------------------------------------------------
  425. ;void xmemcpy(d_seg, d_adrs, s_seg, s_adrs, length)
  426. ;---------------------------------------------------------------
  427.  
  428.  
  429. xmemcpy         proc
  430.                 pushfd                            ;フラグ保存
  431.                 cld
  432.                 push    ecx                     ;ecx 保存
  433.                 push    esi                     ;esi 保存
  434.                 push    edi                     ;edi 保存
  435.                 mov     cx,es                    ;es 保存
  436.                 push    ecx
  437.                 mov     cx,ds                    ;ds 保存
  438.                 push    ecx
  439. #para            equ     ((4*6)+4)
  440.                 mov     ecx,ss:[esp+#para]        ;es ← d_seg
  441.                 mov     es,cx
  442.                 mov     edi,ss:[esp+#para+4]    ;edi ← d_adrs
  443.                 mov     ecx,ss:[esp+#para+8]    ;ds ← s_seg
  444.                 mov     ds,cx
  445.                 mov     esi,ss:[esp+#para+12]    ;esi ← s_adrs
  446.                 mov     ecx,ss:[esp+#para+16]    ;ecx ← length
  447.                 mov     eax,ecx                 ;eax ← ecx (カウンタ保存)
  448.                 shr     ecx,2
  449.                 or        ecx,ecx
  450.                 jz        #0
  451.                 rep movsd
  452. #0:             mov     ecx,eax
  453.                 and     ecx,3
  454.                 jz        #1
  455.                 rep movsb
  456. #1:             pop     ecx                     ;ds 復帰
  457.                 mov     ds,cx
  458.                 pop     ecx                     ;es 復帰
  459.                 mov     es,cx
  460.                 pop     edi                     ;edi 復帰
  461.                 pop     esi                     ;esi 復帰
  462.                 pop     ecx                     ;ecx 復帰
  463.                 popfd                            ;フラグ復帰
  464.                 ret
  465. xmemcpy         endp
  466.  
  467.  
  468.  
  469. ;---------------------------------------------------------------
  470. ;void xymemcpy( d_seg, d_adrs, s_seg, s_adrs, x_cnt, y_cnt,
  471. ;                  0      1         2        3        4        5
  472. ;                d_y_adrs_add, s_y_adrs_add
  473. ;                      6             7
  474. ;---------------------------------------------------------------
  475.  
  476. xymemcpy        proc
  477.                 pushfd                            ;フラグ,edi,esi,ds,esを保存
  478.                 push    edi
  479.                 push    esi
  480.                 mov     ax,ds
  481.                 push    eax
  482.                 mov     ax,es
  483.                 push    eax
  484. #para    equ     4+20
  485.                 cld
  486.                 mov     eax,[esp+#para]         ;es:edi ← 転送先アドレス
  487.                 mov     es,ax
  488.                 mov     edi,[esp+#para+4]
  489.                 mov     eax,[esp+#para+8]        ;ds:esi ← 転送元アドレス
  490.                 mov     ds,ax
  491.                 mov     esi,[esp+#para+12]
  492.                 mov     edx,[esp+#para+20]        ;edx ← Y 方向カウンタ
  493.                 #0:
  494.                         or        edx,edx
  495.                         jz        #1
  496.                         mov     ecx,[esp+#para+16]        ;ecx ← X 方向カウンタ
  497.                         push    edi
  498.                         push    esi
  499.                         push    ecx
  500.                         shr     ecx,2                    ;まず 4 バイトづつ転送
  501.                         rep movsd
  502.                         pop     ecx
  503.                         and     ecx,11b
  504.                         rep movsb                        ;残りの0~3バイトを転送
  505.                         pop     esi
  506.                         pop     edi
  507.                         add     edi,[esp+#para+24]        ;転送先アドレス増加
  508.                         add     esi,[esp+#para+28]        ;転送元アドレス増加
  509.                         dec     edx
  510.                 jmp     #0
  511.                 #1:
  512.                 pop     eax                     ;フラグ,edi,esi,ds,esを復帰
  513.                 mov     es,ax
  514.                 pop     eax
  515.                 mov     ds,ax
  516.                 pop     esi
  517.                 pop     edi
  518.                 popfd
  519.                 ret
  520. xymemcpy        endp
  521.  
  522.  
  523. xyzoommemcpy    proc
  524.  
  525.  
  526.                 
  527.                 lodsd                            ;ebx ← 転送元データ
  528.                 mov     ebx,eax
  529.                 mov     eax,00000001h            ;eax ← 転送先データ
  530.                 mov     ch,8                    ;ch ← 転送元・ニブルカウンタ
  531.                 mov     cl,2                    ;cl ← 縮小カウンタ
  532.  
  533.  
  534.                 dec     cl
  535.                 jnz     #3
  536.                         mov     cl,2
  537.                         shld    eax,ebx,4
  538.                         jnc     #1
  539.                                 stosd
  540.                                 mov     eax,00000001h
  541.                         #1:
  542.                         jmp     #4
  543.                 #3:
  544.                         shl     ebx,4
  545.                 #4:
  546.                 dec     ch
  547.                 jnz     #2
  548.                         mov     ch,8
  549.                         xchg    eax,ebx
  550.                         lodsd
  551.                         xchg    eax,ebx
  552.                 #2:
  553.  
  554.  
  555.  
  556.                 ret
  557. xyzoommemcpy    endp
  558.  
  559.  
  560.                 align    4
  561.  
  562. gray            dd        0
  563. pageadr         dd        0
  564. rgb1            dd        0
  565.                 dd        0
  566.                 dd        0
  567. rgb0            dd        0
  568.                 dd        0
  569.                 dd        0
  570. rgb_            dd        0
  571.                 dd        0
  572.                 dd        0
  573. score            dd        0
  574.                 dd        0
  575.                 dd        0
  576. score_q         dd        0
  577. color            dd        0
  578. vramsel         dd        0
  579.  
  580.  
  581. graypset        proc
  582.                 push    ebx
  583.                 push    esi
  584.                 push    edi
  585.                 pushfd
  586.                 mov     eax,[esp+16+4]
  587.                 mov     ebx,[esp+16+8]
  588.                 mov     ecx,[esp+16+12]
  589.                 mov     edx,[esp+16+16]
  590.                 call    _graypset
  591.                 popfd
  592.                 pop     edi
  593.                 pop     esi
  594.                 pop     ebx
  595.                 ret
  596. graypset        endp
  597.  
  598.  
  599. graypset_list    proc
  600.         ;void graypset_list(struct {int x,y,col,gray} *listp);
  601.                 push    ebx
  602.                 push    esi
  603.                 push    edi
  604.                 pushfd
  605.                 mov     eax,[esp+16+4]
  606.                 call    _graypset_list
  607.                 popfd
  608.                 pop     edi
  609.                 pop     esi
  610.                 pop     ebx
  611.                 ret
  612. graypset_list    endp
  613.  
  614.  
  615. _graypset        proc
  616. ;        in eax:x ebx:y ecx:color edx:gray
  617.                 push    es
  618.                 mov     edi,[_nowscrmod]
  619.                 cmp     edi,10
  620.                 jne     #mode_not10
  621.                         ;★mode 10
  622.                         mov     di,104h         ;es ← VRAM セレクタ
  623.                         mov     es,di
  624.                         mov     [pageadr],0
  625.                         cmp     [_wrtpage],0
  626.                         je        #0
  627.                                 mov     [pageadr],40000h
  628.                         #0:
  629.                         call    _graypset_sub
  630.                         jmp     #endcase_mode
  631.                 #mode_not10:
  632.                 cmp     edi,17
  633.                 jne     #endcase_mode
  634.                         ;★mode 17
  635.                         mov     di,10ch         ;es ← VRAM セレクタ
  636.                         mov     es,di
  637.                         mov     [pageadr],0
  638.                         call    _graypset_sub
  639.                 #endcase_mode:
  640.                 pop     es
  641.                 ret
  642. _graypset        endp
  643.  
  644.  
  645. _graypset_list    proc
  646.         ;in  eax:リストへのポインタ
  647.         ;     (リスト要素:  x,y,col,gray    終端:gray=0ffffffffh)
  648.  
  649.                 push    es
  650.  
  651.                 mov     esi,[_nowscrmod]
  652.                 cmp     esi,10
  653.                 jne     #mode_not10
  654.                         ;★mode 10
  655.                         mov     si,104h
  656.                         mov     es,si
  657.                         mov     [pageadr],0
  658.                         cmp     [_wrtpage],0
  659.                         je        #2
  660.                                 mov     [pageadr],40000h
  661.                         #2:
  662.                         jmp     #endcase_mode
  663.                 #mode_not10:
  664.                         ;★mode 17
  665.                         mov     si,10ch
  666.                         mov     es,si
  667.                         mov     [pageadr],0
  668.                 #endcase_mode:
  669.  
  670.                 mov     esi,eax
  671.                 #0:
  672.                         mov     eax,[esi]
  673.                         mov     ebx,[esi+4]
  674.                         mov     ecx,[esi+8]
  675.                         mov     edx,[esi+12]
  676.                         cmp     edx,0ffffffffh
  677.                         je        #1
  678.                         push    esi
  679.                         call    _graypset_sub
  680.                         pop     esi
  681.                         add     esi,16
  682.                 jmp     #0
  683.                 #1:
  684.  
  685.                 pop     es
  686.                 ret
  687.  
  688. _graypset_list    endp
  689.  
  690.  
  691. _graypset_sub    proc
  692.  
  693. ;        in eax:x, ebx:y, ecx:color, edx:gray(0..256)
  694. ;           [pageadr], es(VRAM selector)
  695.  
  696.                 mov     [gray],edx
  697.                 mov     [color],ecx
  698.                 mov     edi,[_nowscrmod]
  699.                 cmp     edi,10
  700.                 je        #graypset_32K
  701.                 cmp     edi,17
  702.                 je        #graypset_32K
  703.  
  704. #graypset_16:
  705.                 cmp     edx,0
  706.                 je        #end
  707.         ;アドレス計算→ ebx
  708.                 shl     ebx,9            ;ebx := (y*512 + x/2) & 0xfffffffc;
  709.                 mov     edi,eax
  710.                 shr     edi,1
  711.                 add     ebx,edi
  712.                 and     ebx,0fffffffch
  713.                 add     ebx,[pageadr]
  714.         ;マスク算出→ eax、カラーシフト→ edx
  715.                 mov     ecx,eax
  716.                 and     ecx,111b
  717.                 shl     ecx,2
  718.                 mov     eax,1111b
  719.                 shl     eax,cl
  720.                 mov     edx,[color]
  721.                 and     edx,1111b
  722.                 shl     edx,cl
  723.         ;ドット書き込み
  724.                 mov     edi,es:[ebx]
  725.                 not     eax
  726.                 and     edi,eax
  727.                 not     eax
  728.                 or        edi,edx
  729.                 mov     es:[ebx],edi
  730.                 jmp     #end
  731.  
  732. #graypset_32K:
  733.         ;アドレス計算→ ebx
  734.                 shl     ebx,10            ;ebx := y*1024 + x*2 + [pageadr]
  735.                 add     ebx,eax
  736.                 add     ebx,eax
  737.                 add     ebx,[pageadr]
  738.         ;濃度の特例により分岐
  739.                 cmp     edx,256
  740.                 je        #gray256
  741.                 cmp     edx,0
  742.                 je        #end
  743.         ;(濃度 1..255 による描画)
  744.         ;目的色の三原色を抽出
  745.                 mov     eax,ecx         ;eax ← 目的色
  746.                 and     eax,1fh
  747.                 mov     [rgb1+8],eax    ;blue
  748.                 shr     ecx,5            ;目的色を右に5ビットシフト
  749.                 mov     eax,ecx
  750.                 and     eax,1fh
  751.                 mov     [rgb1],eax        ;red
  752.                 shr     ecx,5
  753.                 mov     eax,ecx
  754.                 and     eax,1fh
  755.                 mov     [rgb1+4],eax    ;green
  756.         ;元色の三原色を抽出
  757.                 mov     cx,es:[ebx]
  758.                 mov     eax,ecx
  759.                 and     eax,1fh
  760.                 mov     [rgb0+8],eax    ;blue
  761.                 shr     ecx,5
  762.                 mov     eax,ecx
  763.                 and     eax,1fh
  764.                 mov     [rgb0],eax        ;red
  765.                 shr     ecx,5
  766.                 mov     eax,ecx
  767.                 and     eax,1fh
  768.                 mov     [rgb0+4],eax    ;green
  769.         ;各原色についての評価値を計算
  770.                 mov     ecx,0
  771.                 #0:
  772.                         mov     eax,[rgb0+ecx*4]        ;score = abs(rgb0-rgb1)
  773.                         sub     eax,[rgb1+ecx*4]
  774.                         jnc     #1
  775.                                 neg     eax
  776.                         #1:
  777.                         mov     [score+ecx*4],eax
  778.                         inc     ecx
  779.                         cmp     ecx,3
  780.                 jl        #0
  781.         ;評価基準値の決定 (評価値が全て同じの場合は特例処理)
  782.                 mov     eax,[score]
  783.                 cmp     eax,[score+4]
  784.                 jne     #2
  785.                 cmp     eax,[score+8]
  786.                 jne     #2
  787.                     ;(評価値がすべて同じの場合)
  788.                     ;評価値←元色の原色値  ,   評価基準値←評価値の最小値
  789.                         mov     eax,[rgb0]
  790.                         mov     [score],eax
  791.                         mov     ecx,[rgb0+4]
  792.                         mov     [score+4],ecx
  793.                         cmp     eax,ecx
  794.                         jle     #3
  795.                                 mov     eax,ecx
  796.                         #3:
  797.                         mov     ecx,[rgb0+8]
  798.                         mov     [score+8],ecx
  799.                         cmp     eax,ecx
  800.                         jle     #4
  801.                                 mov     eax,ecx
  802.                         #4:
  803.                         jmp     #5
  804.                 #2:
  805.                     ;(評価値がすべて同じではない場合)
  806.                     ;評価基準値←評価値の最大値
  807.                         mov     eax,[score]
  808.                         mov     ecx,[score+4]
  809.                         cmp     eax,ecx
  810.                         jge     #6
  811.                                 mov     eax,ecx
  812.                         #6:
  813.                         mov     ecx,[score+8]
  814.                         cmp     eax,ecx
  815.                         jge     #7
  816.                                 mov     eax,ecx
  817.                         #7:
  818.                 #5:
  819.                 mov     [score_q],eax
  820.         ;描画色の決定
  821.                 mov     ecx,0
  822.                 #8:
  823.                         mov     eax,[rgb0+ecx*4]
  824.                         cmp     eax,[rgb1+ecx*4]
  825.                         jne     #9
  826.                                 mov     [rgb_+ecx*4],eax
  827.                                 jmp     #10
  828.                         #9:
  829.                                 mov     edx,[score+ecx*4]
  830.                                 cmp     edx,[score_q]
  831.                                 jne     #11
  832.                                         cmp     eax,[rgb1+ecx*4]
  833.                                         mov     eax,0
  834.                                         jge     #12
  835.                                                 mov     eax,255
  836.                                         #12:
  837.                                         jmp     #13
  838.                                 #11:
  839.                                         mov     eax,128
  840.                                 #13:
  841.                                 push    eax     ;補正値の保存
  842.                                 mov     eax,[rgb1+ecx*4]
  843.                                 mov     edx,[gray]
  844.                                 mul     edx     ;edx:eax := edx * eax
  845.                                 mov     edi,eax
  846.                                 mov     eax,[rgb0+ecx*4]
  847.                                 mov     edx,[gray]
  848.                                 neg     edx
  849.                                 add     edx,256
  850.                                 mul     edx     ;edx:eax := edx * eax
  851.                                 add     eax,edi
  852.                                 pop     edx
  853.                                 add     eax,edx
  854.                                 shr     eax,8
  855.                                 cmp     eax,[rgb0+ecx*4]
  856.                                 jne     #20
  857.                                         mov     edx,[rgb0+ecx*4]
  858.                                         cmp     edx,[rgb1+ecx*4]
  859.                                         jg        #21
  860.                                         je        #22
  861.                                                 inc     eax
  862.                                                 jmp     #22
  863.                                         #21:
  864.                                                 dec     eax
  865.                                         #22:
  866.                                 #20:
  867.                                 mov     [rgb_+ecx*4],eax
  868.                         #10:
  869.                         inc     ecx
  870.                         cmp     ecx,3
  871.                 jl        #8
  872.         ;描画
  873.                 mov     eax,[rgb_+4]
  874.                 shl     eax,5
  875.                 or        eax,[rgb_]
  876.                 shl     eax,5
  877.                 or        eax,[rgb_+8]
  878.                 and     eax,7fffh
  879.                 mov     es:[ebx],ax
  880.                 jmp     #end
  881. #gray256:
  882.         ;濃度256(混合無し)による描画
  883.                 and     ecx,7fffh
  884.                 mov     es:[ebx],cx
  885. #end:
  886.                 ret
  887.  
  888. #debugpset:
  889.                 mov     ecx,[color]
  890.                 mov     es:[ebx],cx
  891.                 ret
  892.  
  893. _graypset_sub    endp
  894.  
  895.  
  896. ;------------------------------------------------------------------
  897. ;     ワード単位・メモリアクセスルーチン群
  898. ;------------------------------------------------------------------
  899.  
  900. ;void MEMstoreword_xor(int seg, char *top_adrs, int data, int cnt)
  901. ;void MEMstoreword(int seg, char *top_adrs, int data, int cnt)
  902.  
  903. MEMstoreword    proc
  904.                 mov     ax,es
  905.                 push    eax
  906.                 push    ebx
  907.                 push    edi
  908.                 pushfd
  909.                 cld
  910.                 mov     eax,[esp+4+16]            ;seg
  911.                 mov     es,ax
  912.                 mov     edi,[esp+4+16+4]        ;top_adrs
  913.                 mov     eax,[esp+4+16+8]        ;data
  914.                 mov     ecx,[esp+4+16+12]        ;cnt
  915.                 or        ecx,ecx
  916.                 jz        #0
  917.                 rep stosw        ;[ES:DI]:=AX,DI+=2, repeat until CX=0
  918. #0:             popfd
  919.                 pop     edi
  920.                 pop     ebx
  921.                 pop     eax
  922.                 mov     es,ax
  923.                 ret
  924. MEMstoreword    endp
  925.  
  926. MEMstoreword_xor proc
  927.                 mov     ax,es
  928.                 push    eax
  929.                 push    ebx
  930.                 push    edi
  931.                 pushfd
  932.                 cld
  933.                 mov     eax,[esp+4+16]            ;seg
  934.                 mov     es,ax
  935.                 mov     edi,[esp+4+16+4]        ;top_adrs
  936.                 mov     eax,[esp+4+16+8]        ;data
  937.                 mov     ecx,[esp+4+16+12]        ;cnt
  938.                 ;8ワードずつ処理
  939.                 mov     ebx,ecx
  940.                 shr     ebx,3
  941.                 #2:
  942.                         or        ebx,ebx
  943.                         jz        #1
  944.                         xor     es:[edi   ],ax
  945.                         xor     es:[edi+ 2],ax
  946.                         xor     es:[edi+ 4],ax
  947.                         xor     es:[edi+ 6],ax
  948.                         xor     es:[edi+ 8],ax
  949.                         xor     es:[edi+10],ax
  950.                         xor     es:[edi+12],ax
  951.                         xor     es:[edi+14],ax
  952.                         add     edi,16
  953.                         dec     ebx
  954.                 jmp     #2
  955.                 #1:
  956.                 ;のこりの0~7ワードを処理
  957.                 and     ecx,7
  958.                 #3:
  959.                         or        ecx,ecx
  960.                         jz        #4
  961.                         xor     es:[edi],ax
  962.                         inc     edi
  963.                         inc     edi
  964.                         dec     ecx
  965.                 jmp     #3
  966.                 #4:
  967.                 ;後処理
  968.                 popfd
  969.                 pop     edi
  970.                 pop     ebx
  971.                 pop     eax
  972.                 mov     es,ax
  973.                 ret
  974. MEMstoreword_xor endp
  975.  
  976.  
  977. ;---------------------------------------------------------------
  978. ;    makeHLSgradline(char *gbuf,len,r1,g1,b1,rr,gr,br)
  979. ;        HLS 三角形描画時のグラデーション作成補助ルーチン
  980. ;
  981. ;    gbuf からの len ドット分を、始点色(r1,g1,b1), 傾き(rr,gr,br)
  982. ;    のグラデーションで埋める
  983. ;    r1,g1,b1,rr,gr,br は10ビット固定小数点数。
  984. ;        for (i=0; i<l; i++, sr+=sr_r,sg+=sg_r,sb+=sb_r)
  985. ;            gbuf[i] = GRB(sg>>DECIMAL,sr>>DECIMAL,sb>>DECIMAL);
  986. ;---------------------------------------------------------------
  987.  
  988. makeHLSgradline    proc
  989.                 pushfd
  990.                 push    ebx
  991.                 push    edi
  992.                 push    esi
  993.                 #para equ 20
  994.                 mov        edi,ss:[esp+#para+0]
  995.                 mov        esi,ss:[esp+#para+4]
  996.                 mov        ebx,ss:[esp+#para+12]
  997.                 mov        ecx,ss:[esp+#para+8]
  998.                 mov        edx,ss:[esp+#para+16]
  999.                 mov        eax,ss:[esp+#para+24]
  1000.                 mov        ds:[wk0],eax
  1001.                 mov        eax,ss:[esp+#para+20]
  1002.                 mov        ds:[wk1],eax
  1003.                 mov        eax,ss:[esp+#para+28]
  1004.                 mov        ds:[wk2],eax
  1005.                 inc        esi
  1006.                 #1:
  1007.                     dec        esi
  1008.                     jz        #0
  1009.                     sub        eax,eax
  1010.                     ror        ebx,10        ;G
  1011.                     add        ax,bx
  1012.                     rol        ebx,10
  1013.                     shl        eax,5
  1014.                     ror        ecx,10        ;R
  1015.                     add        ax,cx
  1016.                     rol        ecx,10
  1017.                     shl        eax,5
  1018.                     ror        edx,10        ;B
  1019.                     add        ax,dx
  1020.                     rol        edx,10
  1021.                     mov        [edi],ax
  1022.                     add        edi,2
  1023.                     add        ebx,ds:[wk0]    ;G:=G+dG
  1024.                     add        ecx,ds:[wk1]    ;R:=R+dR
  1025.                     add        edx,ds:[wk2]    ;B:=B+dB
  1026.                 jmp        #1
  1027.                 #0:
  1028.                 pop        esi
  1029.                 pop        edi
  1030.                 pop        ebx
  1031.                 popfd
  1032.                 ret
  1033. makeHLSgradline    endp
  1034.  
  1035.  
  1036. cseg ends
  1037.  
  1038. end
  1039.